package com.kiven.file;

import java.io.File;

public class FindAndReadFile {
	//控制缩进的距离
	private int level = 0;
	/*private File file = null;
	
	public FindAndReadFile(String fileName) {
		this.file = new File(fileName);
	}
	
	public void getDir(int level) {
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<level;i++) {
			sb.append("----");
		}
		
		System.out.println(file.getName());
		
		File[] files = file.listFiles();
		
		for(File file : files) {
			System.out.println(file.getName());
			
			if(file.isDirectory()) {
				this.getDir(level++);
			}
		}
	}*/
	//sdfsfsd
	
	public void getDir(File file,int level ) {
		this.level = level;
		StringBuffer sb = new StringBuffer();
		for(int i=0; i<level; i++) {
			sb.append("----");
		}
		System.out.print(sb.toString());
		
		//File file = new File(str);
		
		for(File f : file.listFiles()) {
			System.out.println(f.getName());
			if(f.isDirectory()) {
				getDir(f,level++);
			}
		}
	}
	
	public static void main(String[] args) {
		new FindAndReadFile().getDir(new File("/home/liqingwen/文档"), 0);
	}
}
